package com.example.administrator.js_bank;


import android.annotation.TargetApi;
import android.content.Context;

import android.graphics.drawable.Drawable;
import android.os.Build;

import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {

    private ImageView mIvcehua;
    private DrawerLayout drawerLayout;
    RadioButton mRbSouye, btn_xyk, mRbLicai, mRbDaikuan;
    List<Fragment> FragmentList;
    RadioGroup mRadioGroup;
    ViewPager vPager;
    //Context context;
    private static final String TAG = "MainActivity";


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        drawerLayout = findViewById(R.id.drawlayout);
        btn_xyk = findViewById(R.id.bt_xyk);
        mRbSouye = findViewById(R.id.souye);
        mRbLicai = findViewById(R.id.licai);
        mRbDaikuan = findViewById(R.id.daikuan);
        mIvcehua = findViewById(R.id.IV_caidan);

        initView();
        MyFragment fragment = new MyFragment();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction beginTransaction = fm.beginTransaction();
        beginTransaction.add(R.id.rl, fragment);
        beginTransaction.commit();

        List<Fragment> fragments = new ArrayList<Fragment>();
        fragments.add(new Fragment1());
        fragments.add(new Fragment2());
        fragments.add(new Fragment3());
        fragments.add(new Fragment4());

        FragAdapter adapter = new FragAdapter(getSupportFragmentManager(), fragments);
        vPager = findViewById(R.id.viewpager);

        mRadioGroup= findViewById(R.id.rg_home);
        mRadioGroup.setOnCheckedChangeListener(this);
        vPager.setAdapter(adapter);


        mIvcehua.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.openDrawer(Gravity.LEFT);

            }
        });

    }


    private void init() {

        Intent intent = new Intent(this, Main2Activity.class);
        startActivity(intent);
    }

    public void longpay(View view) {
        Intent intent = new Intent(this, LongPayActivity.class);
        startActivity(intent);
    }



    public void gg(View view) {
        Intent intent = new Intent(this, Main8Activity.class);
        startActivity(intent);

    }
    public void safe(View view) {

        Intent intent = new Intent(MainActivity.this, SafeActivity.class);
        startActivity(intent);
    }




    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

        }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    public void hu(View view) {

        Intent intent = new Intent(this, Main7Activity.class);
        startActivity(intent);
    }

    class FragAdapter extends FragmentPagerAdapter {

        public FragAdapter(android.support.v4.app.FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            FragmentList = fragments;

        }

        @Override
        public Fragment getItem(int position) {
            return FragmentList.get(position);
        }

        @Override
        public int getCount() {
            return FragmentList.size();
        }


    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){

            case R.id.souye:
                vPager.setCurrentItem(0);
                break;
            case R.id.bt_xyk:
                vPager.setCurrentItem(1);
                break;
            case R.id.licai:
                vPager.setCurrentItem(2);
                break;
            case  R.id.daikuan:
                vPager.setCurrentItem(3);
                break;
        }



    }
    private void initView() {
        //定义底部标签图片大小和位置
        Drawable drawable_news = getResources().getDrawable(R.drawable.selector_bar_1);
        //当这个图片被绘制时，给他绑定一个矩形 ltrb规定这个矩形
        drawable_news.setBounds(0, 0, 50, 50);
        //设置图片在文字的哪个方向
        mRbSouye.setCompoundDrawables(null, drawable_news, null, null);

        //定义底部标签图片大小和位置
        Drawable drawable_live = getResources().getDrawable(R.drawable.yhcard);
        //当这个图片被绘制时，给他绑定一个矩形 ltrb规定这个矩形
        drawable_live.setBounds(0, 0, 50, 50);
        //设置图片在文字的哪个方向
        btn_xyk.setCompoundDrawables(null, drawable_live, null, null);

        //定义底部标签图片大小和位置
        Drawable drawable_tuijian = getResources().getDrawable(R.drawable.tzlicia);
        //当这个图片被绘制时，给他绑定一个矩形 ltrb规定这个矩形
        drawable_tuijian.setBounds(0, 0, 50, 50);
        //设置图片在文字的哪个方向
        mRbLicai.setCompoundDrawables(null, drawable_tuijian, null, null);

        //定义底部标签图片大小和位置
        Drawable drawable_me = getResources().getDrawable(R.drawable.daikuang);
        //当这个图片被绘制时，给他绑定一个矩形 ltrb规定这个矩形
        drawable_me.setBounds(0, 0, 50, 50);
        //设置图片在文字的哪个方向
        mRbDaikuan.setCompoundDrawables(null, drawable_me, null, null);
    }


}
